package com.lyu.travel.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @ProjectName: [travel]
 * @Package: [com.lyu.travel.config]
 * @ClassName: [WebMvcConfig]
 * @Description: webMvc相关配置
 * @Author: [78483]
 * @CreateDate: [2020-06-11 15:56]
 * @UpdateUser: [78483]
 * @UpdateDate: [2020-06-11 15:56]
 * @UpdateRemark: [说明本次修改内容]
 * @Version: [v1.0]
 */
//标识它是一个配置文件
@Configuration
public class WebMvcConfig implements WebMvcConfigurer {
    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        registry.addViewController("/").setViewName("login");
        registry.addViewController("/login").setViewName("login");
        registry.addViewController("/index").setViewName("login");
        registry.addViewController("/index.html").setViewName("login");
        registry.addViewController("/mainPage.html").setViewName("dashboard");
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //注册拦截器
        registry.addInterceptor(new LoginHandlerInterceptor())
        //拦截所有路径
        .addPathPatterns("/**")
                //放开
        .excludePathPatterns("/css/**","/img/**","/js/**","/","/index.html","/login")
        ;
    }

}